/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.siscoh.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.siscoh.model.bean.ClienteBean;
import org.siscoh.model.dao.ClienteDao;

/**
 *
 * @author Israel
 */
public class ControladorCliente extends AbstractController {

    @Override
    public String executa(HttpServletRequest request, HttpServletResponse response) {
        String url = "404.html";
        int acao;
        
        acao = Integer.parseInt(request.getParameter("cod"));

        switch (acao) {
            case Constants.INSERT_CLIENTE:
                url = cadastrarCliente(request, response);
                break;
        }
        

        return url;
    }
    
    private String cadastrarCliente(HttpServletRequest request, HttpServletResponse response)
    {
        String url = "formularios/formcliente?status=";
        String informacao, nome;
        
        informacao = request.getParameter("info");
        nome = request.getParameter("nome");
        
        if(nome == null || informacao == null || nome.equals("") || informacao.equals(""))
        {
            return url+"0";
        }
        else
        {
            ClienteBean cliente = new ClienteBean();
            cliente.setNome(nome);
            cliente.setInformacao(informacao);
            
            new ClienteDao().insert(cliente);
            
        }
        
        return url+"1";
    }
    
    
    
}
